home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / MacODBC / ODBC Tools / SampleTranslate / Sources / ConfigTranslator.c next >
Encoding:
C/C++ Source or Header  |  1995-03-27  |  2.8 KB  |  149 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    ConfigTranslator.c
  3.  *
  4.  *    © 1993 by Apple Computer, Inc., all rights reserved.
  5.  */
  6.  
  7. #include <Controls.h>
  8. #include <Dialogs.h>
  9. #include <Events.h>
  10. #include <Lists.h>
  11. #include <Quickdraw.h>
  12. #include <TextEdit.h>
  13. #include <Types.h>
  14.  
  15. #include "DialogUtilities.h"
  16. #include "ODBCSharedLibraries.h"
  17. #include "ConfigTranslator.h"
  18.  
  19. #define ConfigTranslatorDlogID        132  
  20.  
  21. #define iOKButton                    1 
  22. #define iCancelButton                2 
  23. #define iOption1                    3 
  24. #define iOption2                    4 
  25. #define iOption3                    5 
  26. #define iOption4                    6 
  27. #define iRect1                        7 
  28. #define iOptionsLabel                8 
  29. #define iTitle                        9 
  30. #define iTitleUnderline                10 
  31.  
  32. typedef struct
  33. {
  34.     GrafPtr        savePort;
  35.     DialogPtr    dialog;
  36.     DWORD        *pvOption;
  37. }
  38. ConfigTranslatorRec;
  39.  
  40. static ConfigTranslatorRec            gConfigTranslatorRec;
  41.  
  42. Boolean        Initialize                (WindowPtr parentWindow, DWORD *pvOption);
  43. void        Cleanup                    ();
  44. void        DoTranslationOption        (short itemNr);
  45. Boolean        DoOkButton                ();
  46.  
  47. Boolean
  48. DoConfigTranslator(WindowPtr parentWindow, DWORD *pvOption)
  49. {
  50.     Boolean        result;
  51.     Boolean        done = false;
  52.     short        itemNr;
  53.     
  54.     UPPInit( uppModalFilterProcInfo, StandardFilter )
  55.     
  56.     if (!Initialize(parentWindow, pvOption)) return false;
  57.     
  58.     while (!done)
  59.     {
  60.         ModalDialog( UPP(StandardFilter), &itemNr);
  61.         switch (itemNr)
  62.         {
  63.             case iOKButton:
  64.                 done = result = DoOkButton();
  65.                 break;
  66.             
  67.             case iCancelButton:
  68.                 result = false;
  69.                 done = true;
  70.                 break;
  71.             
  72.             case iOption1:
  73.             case iOption2:
  74.             case iOption3:
  75.             case iOption4:
  76.                 DoTranslationOption(itemNr);
  77.                 break;
  78.         }
  79.     }
  80.     
  81.     Cleanup();
  82.     
  83.     return result;
  84. }
  85.  
  86. UPPInitStatic(uppUserItemProcInfo,DrawItemRect)
  87. UPPInitStatic(uppUserItemProcInfo,DrawItemDoubleLine)
  88.  
  89. Boolean
  90. Initialize(WindowPtr parentWindow, DWORD *pvOption)
  91. {
  92.     DialogPtr    dialog;
  93.     GrafPtr        savePort;
  94.     short        btn;
  95.     
  96.     GetPort(&savePort);
  97.     InitCursor();
  98.     dialog = GetNewDialogOverWindow(ConfigTranslatorDlogID, parentWindow);
  99.     if (dialog == NULL) goto bail;
  100.     SetPort(dialog);
  101.     
  102.     SetDUserItem(dialog, iRect1,            (UniversalProcPtr)UPP(DrawItemRect) );
  103.     SetDUserItem(dialog, iTitleUnderline,    (UniversalProcPtr)UPP(DrawItemDoubleLine) );
  104.     
  105.     gConfigTranslatorRec.savePort = savePort;
  106.     gConfigTranslatorRec.dialog = dialog;
  107.     gConfigTranslatorRec.pvOption = pvOption;
  108.     
  109.     btn = *pvOption + iOption1;
  110.     if (btn < iOption1) btn = iOption1;
  111.     if (btn > iOption4) btn = iOption4;
  112.     SetDRadioButton(dialog, btn, iOption1, iOption4);
  113.     
  114.     ShowWindow(dialog);
  115.     
  116.     return true;
  117.     
  118. bail:
  119.     
  120.     if (dialog != NULL) DisposDialog(dialog);
  121.     SetPort(savePort);
  122.     
  123.     return false;
  124. }
  125.  
  126. void
  127. Cleanup()
  128. {
  129.     DisposDialog(gConfigTranslatorRec.dialog);
  130.     SetPort(gConfigTranslatorRec.savePort);
  131. }
  132.  
  133. Boolean
  134. DoOkButton()
  135. {
  136.     short    btn;
  137.     
  138.     btn = GetDRadioButton(gConfigTranslatorRec.dialog, iOption1, iOption4);
  139.     *(gConfigTranslatorRec.pvOption) = btn - iOption1;
  140.     
  141.     return true;
  142. }
  143.  
  144. void
  145. DoTranslationOption(short itemNr)
  146. {
  147.     SetDRadioButton(gConfigTranslatorRec.dialog, itemNr, iOption1, iOption4);
  148. }
  149.